package com.prothink.threadadmindemo.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@RequestMapping("/menus")
@RestController
public class MajinyiController {
    public static class ListNode {
        int val;
        ListNode next;
        ListNode(int x) { val = x; }
    }

    public static ListNode reverseList(ListNode head) {
        ListNode prev = null;
        ListNode current = head;
        ListNode next = null;

        while (current != null) {
            next = current.next; // 保存下一个节点
            current.next = prev; // 反转当前节点指针
            prev = current;      // 移动prev到当前节点
            current = next;      // 移动current到下一个节点
        }

        return prev; // 最终prev指向新的头节点
    }

    public static void main(String[] args) {
        // 创建一个简单的链表：1 -> 2 -> 3 -> 4 -> 5
        ListNode head = new ListNode(1);
        head.next = new ListNode(2);
        head.next.next = new ListNode(3);
        head.next.next.next = new ListNode(4);
        head.next.next.next.next = new ListNode(5);

        // 反转链表
        ListNode reversedHead = reverseList(head);

        // 打印反转后的链表
        ListNode node = reversedHead;
        while (node != null) {
            System.out.print(node.val + " ");
            node = node.next;
        }
    }



}
